<?php

namespace app\admin\controller;

use app\admin\controller\Base;
use think\Db;

/**
 * 用户组管理
 * Class GroupController
 * @package app\admin\controller\auth
 */
class Count extends Base
{


    public function index()
    {
        return view();
    }

    public function lists()
    {

        $noun = config('param.noun');
        $tesk_ok = config('param.test_ok');
        $city = config('param.city');
        $sub_city = config('param.sub_city');
        $sex = config('param.sex');

        $item = [];

        foreach ($sub_city as $key => $info) {
            $item2 = [];
            $item2['c1'] = $info;
            $item2['c2'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('noun', 1)->count();
            $item2['c3'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('noun', 2)->count();

            $item2['c4'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->whereTime('test_1_time', 'today')->count();
            $item2['c5'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->whereTime('test_1_time', 'today')->where('test_1_status', 1)->count();
            $item2['c6'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->whereTime('test_1_time', 'today')->where('test_1_status', 2)->count();
            $item2['c7'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->whereTime('test_1_time', 'today')->where('test_1_status', 4)->count();
            $item2['c8'] = $item2['c2'] + $item2['c3'] - $item2['c4'];

            $item2['c9'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('noun', 1)->where('medical_time', '<', 88)->count();
            $item2['c10'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('noun', 2)->where('medical_time', '<', 88)->count();
            $item2['c11'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_1_time', '>', 88)->count();
            $item2['c12'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_1_time', '>', 88)->where('test_1_status', 1)->count();
            $item2['c13'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_1_time', '>', 88)->where('test_1_status', 2)->count();
            $item2['c14'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_1_time', '>', 88)->where('test_1_status', 4)->count();
            $item2['c15'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_2_time', '>', 88)->count();
            $item2['c16'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_2_time', '>', 88)->where('test_2_status', 1)->count();
            $item2['c17'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_2_time', '>', 88)->where('test_2_status', 2)->count();
            $item2['c18'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', '<', 'today')->where('medical_time', '<', 88)->where('test_2_time', '>', 88)->where('test_2_status', 4)->count();
            $item2['c19'] = $item2['c9'] + $item2['c10'] - $item2['c11'];

            $item2['c20'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igm', 1)->count();
            $item2['c21'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igm', 2)->count();
            $item2['c22'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igm', 3)->count();
            $item2['c23'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igg', 1)->count();
            $item2['c24'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igg', 2)->count();
            $item2['c25'] = DB::name('user')->where('sub_city', $key)->whereTime('visa_time', 'today')->where('igg', 3)->count();
            $item2['c26'] = DB::name('user')->where('sub_city', $key)->where('igm', 1)->count();
            $item2['c27'] = DB::name('user')->where('sub_city', $key)->where('igm', 2)->count();
            $item2['c28'] = DB::name('user')->where('sub_city', $key)->where('igm', 3)->count();
            $item2['c29'] = DB::name('user')->where('sub_city', $key)->where('igg', 1)->count();
            $item2['c30'] = DB::name('user')->where('sub_city', $key)->where('igg', 2)->count();
            $item2['c31'] = DB::name('user')->where('sub_city', $key)->where('igg', 3)->count();
            $item2['c32'] = DB::name('user')->where('sub_city', $key)->whereTime('free_isolate_time', 'today')->count();
            $item2['c33'] = DB::name('user')->where('sub_city', $key)->where('noun', 1)->count();
            $item2['c34'] = DB::name('user')->where('sub_city', $key)->where('noun', 2)->count();
            $item[] = $item2;

        }
       // dump($item);
//       echo 'c';
//        dump($item[0]['c2']);
      //  exit;
        $item2 = [];
        $item2['c1'] = '总计';
        for ($i2 = 2; $i2 <= 34; $i2++) {
            $item2['c' .$i2] =0;
        }
        foreach ($sub_city as $key => $info) {
//            dump($key);

            for ($i2 = 2; $i2 <= 34; $i2++) {
               // dump($item[$key-1]['c' .$i2]);
                $item2['c' .$i2] += $item[$key-1]['c' .$i2];
            }
        }


        $item[] = $item2;
        $data['data'] = $item;
        $data['count'] = count($data['data']);


        if ($data['count'] > 0 && $data['data']) {
            $data['msg'] = '获取成功';
        } else {
            $data['msg'] = '获取数据为空';
        }
        $data['code'] = 0;
        return json($data);
    }

    public function status()
    {

        $this->assign('yes_no', config('param.yes_no'));
        $this->assign('noun', config('param.noun'));
        $this->assign('isolate_status', config('param.isolate_status'));
        $this->assign('move_status', config('param.move_status'));
        $this->assign('test_ok', config('param.test_ok'));
        $this->assign('job', config('param.job'));
        $this->assign('city', config('param.city'));
        $this->assign('sub_city', config('param.sub_city'));
        $this->assign('sex', config('param.sex'));

    }


}